﻿using System.Web.Mvc;
using System.Web.Routing;
using SharpArch.Web.Areas;

namespace good1.Web.Controllers
{
    public class RouteRegistrar
    {
        //TODO: move to utility space as not a controller but a utility used by controllers.
        public static void RegisterRoutesTo(RouteCollection routes)
        {
            const string validationMaxIdLength = @"\d{1,5}";

            routes.IgnoreRoute("elmah.axd");  //TODO: confirm this is taken care of with line below
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

            routes.CreateArea("Search", "good1.Web.Controllers",
                              routes.MapRoute("SearchProjects", "search/projects",
                                              new {controller = "Project", action = "Search"}));

            //validationMaxIdLength ensures we don't overmatch routes we want dealt with below
            routes.CreateArea("Root", "good1.Web.Controllers",
                   routes.MapRoute(null, "{controller}/{id}/{title}", new { controller = "Home", action = "Show", title = "" }, new { id = validationMaxIdLength })
            );
            
            routes.CreateArea("Root", "good1.Web.Controllers",
                   routes.MapRoute(null, "{controller}/{action}/{id}/{title}", new { controller = "Home", action = "Index", id = "", title = "" })
            );

            routes.CreateArea("Root", "good1.Web.Controllers",
                routes.MapRoute(null, "{controller}/{action}", new { controller = "Home", action = "Index" }),
                routes.MapRoute(null, "{controller}/{action}/{id}")
            );

         }
    }
}
